<template>
  <div class="basic-info">
    <el-form :model="form" ref="form" label-width="88px" size="mini" :rules="addRules" :disabled="formDisabled || mode === 'view'">
      <el-row :gutter="24">

        <el-col :xs="24" :sm="24" :md="12" :lg="6" :xl="6">
          <el-form-item label="高危药品：" prop="highRisk">
            <el-select v-model="form.highRisk" @change="updateForm">
              <el-option 
                v-for="item in highRiskOption" 
                :key="item.value" 
                :label="item.label" 
                :value="item.id">
              </el-option>
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :xs="24" :sm="24" :md="12" :lg="6" :xl="6">
          <el-form-item label="是否液体：" prop="liquid">
            <el-select v-model="form.liquid" @change="updateForm">
              <el-option 
                v-for="item in liquidOptions" 
                :key="item.value" 
                :label="item.label" 
                :value="item.id">
              </el-option>
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :xs="24" :sm="24" :md="12" :lg="6" :xl="6">
          <el-form-item label="质量类别：" prop="qltType">
            <el-select v-model="form.qltType" @change="updateForm">
              <el-option 
                v-for="item in qualityCategory" 
                :key="item.value" 
                :label="item.label" 
                :value="item.value">
              </el-option>
            </el-select>
          </el-form-item>
        </el-col>

        <!-- 临床用途、激素药品等 -->
        <el-col :xs="24" :sm="24" :md="6" :lg="6" :xl="6">
          <el-form-item label="临床用途：" prop="clncUse">
            <el-select v-model="form.clncUse" @change="updateForm" disabled>
              <el-option 
                v-for="item in YNoptions" 
                :key="item.value" 
                :label="item.label" 
                :value="item.id">
              </el-option>
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :xs="24" :sm="24" :md="6" :lg="6" :xl="6">
          <el-form-item label="激素药品：" prop="hormone">
            <el-select v-model="form.hormone" @change="updateForm">
              <el-option 
                v-for="item in YNoptions" 
                :key="item.value" 
                :label="item.label" 
                :value="item.id">
              </el-option>
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :xs="24" :sm="24" :md="6" :lg="6" :xl="6">
          <el-form-item label="妊娠药品：" prop="prey">
            <el-select v-model="form.prey" @change="updateForm">
              <el-option 
                v-for="item in YNoptions" 
                :key="item.value" 
                :label="item.label" 
                :value="item.id">
              </el-option>
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :xs="24" :sm="24" :md="6" :lg="6" :xl="6">
          <el-form-item label="院内制剂：" prop="hospPrep">
            <el-select v-model="form.hospPrep" @change="updateForm">
              <el-option 
                v-for="item in YNoptions" 
                :key="item.value" 
                :label="item.label" 
                :value="item.id">
              </el-option>
            </el-select>
          </el-form-item>
        </el-col>

        <!-- 抗肿瘤、重点监控等 -->
        <el-col :xs="24" :sm="24" :md="12" :lg="6" :xl="6">
          <el-form-item label="抗肿瘤：" prop="retTur">
            <el-select v-model="form.retTur" @change="updateForm">
              <el-option 
                v-for="item in YNoptions" 
                :key="item.value" 
                :label="item.label" 
                :value="item.id">
              </el-option>
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :xs="24" :sm="24" :md="12" :lg="6" :xl="6">
          <el-form-item label="重点监控：" prop="mainCtrl">
            <el-select v-model="form.mainCtrl" @change="updateForm">
              <el-option 
                v-for="item in YNoptions" 
                :key="item.value" 
                :label="item.label" 
                :value="item.id">
              </el-option>
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :xs="24" :sm="24" :md="12" :lg="6" :xl="6">
          <el-form-item label="蛋白同化剂：" prop="prnAssePrep">
            <el-select v-model="form.prnAssePrep" @change="updateForm">
              <el-option 
                v-for="item in YNoptions" 
                :key="item.value" 
                :label="item.label" 
                :value="item.id">
              </el-option>
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :xs="24" :sm="24" :md="6" :lg="6" :xl="6">
          <el-form-item label="避光药物：" prop="prodAgatExpo">
            <el-select v-model="form.prodAgatExpo" @change="updateForm">
              <el-option 
                v-for="item in YNoptions" 
                :key="item.value" 
                :label="item.label" 
                :value="item.id">
              </el-option>
            </el-select>
          </el-form-item>
        </el-col>
		<el-col :xs="24" :sm="24" :md="6" :lg="6" :xl="6">
		  <el-form-item label="限定用药：" prop="lmtUsed">
		    <el-select v-model="form.lmtUsed" @change="updateForm">
		      <el-option 
		        v-for="item in YNoptions" 
		        :key="item.value" 
		        :label="item.label" 
		        :value="item.id">
		      </el-option>
		    </el-select>
		  </el-form-item>
		</el-col>
		
        <!-- 基本药物、基药类型等 -->
        <el-col :xs="24" :sm="24" :md="6" :lg="6" :xl="6">
          <el-form-item label="基本药物：" prop="basMedn">
            <el-select v-model="form.basMedn" @change="updateForm">
              <el-option 
                v-for="item in YNoptions" 
                :key="item.value" 
                :label="item.label" 
                :value="item.id">
              </el-option>
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :xs="24" :sm="24" :md="6" :lg="6" :xl="6">
          <el-form-item label="基药类型：" prop="basMednType">
            <el-select 
              v-model="form.basMednType" 
              @change="updateForm" 
              :disabled="form.basMedn !== '1'"
              placeholder="请选择">
              <el-option 
                v-for="item in basicTypeOptions" 
                :key="item.value" 
                :label="item.label" 
                :value="item.id">
              </el-option>
            </el-select>
          </el-form-item>
        </el-col>

        <!-- DDD、来源分类等输入框 -->
        <el-col :xs="24" :sm="24" :md="24" :lg="6" :xl="6">
          <el-form-item label="DDD：" prop="dddvar">
            <el-input 
              v-model="form.dddvar" 
              @blur="updateForm" 
              placeholder="g">
            </el-input>
          </el-form-item>
        </el-col>
        <el-col :xs="24" :sm="24" :md="24" :lg="6" :xl="6">
          <el-form-item label="来源分类：" prop="fromClass">
            <el-input 
              v-model="form.fromClass" 
              @blur="updateForm">
            </el-input>
          </el-form-item>
        </el-col>
        <el-col :xs="24" :sm="24" :md="24" :lg="6" :xl="6">
          <el-form-item label="强度系数：" prop="strhCoet">
            <el-input 
              v-model="form.strhCoet" 
              @blur="updateForm">
            </el-input>
          </el-form-item>
        </el-col>
		<el-col :xs="12" :sm="12" :md="6" :lg="6" :xl="6">
		  <el-form-item label="适用范围：" prop="lmtSpc">
		    <el-select v-model="form.lmtSpc" @change="updateForm">
				<el-option v-for="item in UseOptions" :key="item.id" :label="item.label" :value="item.id">
					<span>{{ item.label }}</span>
				</el-option>
		    </el-select>
		  </el-form-item>
		</el-col>
        <!-- 限定用药、有效状态等 -->
        
        
        <el-col :xs="24" :sm="24" :md="24" :lg="6" :xl="6">
          <el-form-item label="停药天数：" prop="stopDay">
            <el-input 
              v-model="form.stopDay" 
              @blur="updateForm">
            </el-input>
          </el-form-item>
        </el-col>
        <el-col :xs="24" :sm="24" :md="24" :lg="6" :xl="6">
          <el-form-item label="权重：" prop="weit">
            <el-input 
              v-model="form.weit" 
              @blur="updateForm">
            </el-input>
          </el-form-item>
        </el-col>

        <!-- 溶媒量、抗生素等级等 -->
        <el-col :xs="24" :sm="24" :md="24" :lg="6" :xl="6">
          <el-form-item label="溶媒量：" prop="soltquayCnt">
            <el-input 
              v-model="form.soltquayCnt" 
              @blur="updateForm" 
              placeholder="Ml">
            </el-input>
          </el-form-item>
        </el-col>
        <el-col :xs="24" :sm="24" :md="24" :lg="6" :xl="6">
          <el-form-item label="抗生素等级：" prop="antcLv">
            <el-select v-model="form.antcLv" @change="updateForm"
			:disabled="formDisabled || mode === 'view' || formDisabledAntcLv">
              <el-option 
                v-for="item in antcLvOption" 
                :key="item.value" 
                :label="item.label" 
                :value="item.id">
              </el-option>
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :xs="24" :sm="24" :md="24" :lg="6" :xl="6">
          <el-form-item label="储存条件：" prop="stoeConds">
            <el-input 
              v-model="form.stoeConds" 
              @blur="updateForm">
            </el-input>
          </el-form-item>
        </el-col>
        <el-col :xs="24" :sm="24" :md="24" :lg="6" :xl="6">
          <el-form-item label="存储条件：" prop="stoeCons">
            <el-select v-model="form.stoeCons" @change="updateForm">
              <el-option 
                v-for="item in saveOptions" 
                :key="item.value" 
                :label="item.label" 
                :value="item.id">
              </el-option>
            </el-select>
          </el-form-item>
        </el-col>

        <!-- 是否进口、计费范围等 -->
        <el-col :xs="24" :sm="24" :md="24" :lg="6" :xl="6">
          <el-form-item label="是否进口：" prop="importB">
            <el-select v-model="form.importB" @change="updateForm">
              <el-option 
                v-for="item in YNoptions" 
                :key="item.value" 
                :label="item.label" 
                :value="item.id">
              </el-option>
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :xs="24" :sm="24" :md="24" :lg="6" :xl="6">
          <el-form-item label="计费范围：" prop="chargedSpc">
            <el-select v-model="form.chargedSpc" @change="updateForm">
              <el-option 
                v-for="item in chargedSpcOptions" 
                :key="item.value" 
                :label="item.label" 
                :value="item.id">
              </el-option>
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :xs="24" :sm="24" :md="24" :lg="6" :xl="6">
          <el-form-item label="材质：" prop="matl">
            <el-input 
              v-model="form.matl" 
              @blur="updateForm">
            </el-input>
          </el-form-item>
        </el-col>
        <el-col :xs="24" :sm="24" :md="24" :lg="6" :xl="6">
          <el-form-item label="卫材类型：" prop="eisaiType">
            <el-select v-model="form.eisaiType" @change="updateForm" disabled>
              <el-option 
                v-for="item in getEisaiOption" 
                :key="item.value" 
                :label="item.label" 
                :value="item.id">
              </el-option>
            </el-select>
          </el-form-item>
        </el-col>

        <!-- 卫材属性、检验测试等 -->
        <el-col :xs="24" :sm="24" :md="24" :lg="6" :xl="6">
          <el-form-item label="卫材属性：" prop="eisaiAtte">
            <el-select v-model="form.eisaiAtte" @change="updateForm" disabled>
              <el-option 
                v-for="item in eisaiAtteOption" 
                :key="item.value" 
                :label="item.label" 
                :value="item.id">
              </el-option>
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :xs="24" :sm="24" :md="24" :lg="6" :xl="6">
          <el-form-item label="检验测试：" prop="cutOff">
            <el-input 
              v-model="form.cutOff" 
              @blur="updateForm">
            </el-input>
          </el-form-item>
        </el-col>
        <el-col :xs="24" :sm="24" :md="24" :lg="6" :xl="6">
          <el-form-item label="试剂条码：" prop="reatCode">
            <el-input 
              v-model="form.reatCode" 
              @blur="updateForm">
            </el-input>
          </el-form-item>
        </el-col>
        <el-col :xs="24" :sm="24" :md="24" :lg="6" :xl="6">
          <el-form-item label="换算关系：" prop="convnRelp">
            <el-input 
              v-model="form.convnRelp" 
              @blur="updateForm" 
              type="number">
            </el-input>
          </el-form-item>
        </el-col>

        <!-- 允许小数、自备药品等 -->
        <el-col :xs="24" :sm="24" :md="24" :lg="3" :xl="3">
          <el-form-item label="允许小数：" prop="allowDecimal">
            <el-checkbox 
              v-model="form.allowDecimal" 
              @change="updateForm">
            </el-checkbox>
          </el-form-item>
        </el-col>
        <el-col :xs="24" :sm="24" :md="24" :lg="3" :xl="3">
          <el-form-item label="自备药品：" prop="selfProe">
            <el-checkbox 
              v-model="form.selfProe" 
              @change="updateForm">
            </el-checkbox>
          </el-form-item>
        </el-col>
        <el-col :xs="24" :sm="24" :md="24" :lg="6" :xl="6">
          <el-form-item label="对照均值：" prop="compareAvg">
            <el-input 
              v-model="form.compareAvg" 
              @blur="updateForm">
            </el-input>
          </el-form-item>
        </el-col>
        <el-col :xs="24" :sm="24" :md="24" :lg="6" :xl="6">
          <el-form-item label="养护：" prop="nurtureb">
            <el-select v-model="form.nurtureb" @change="updateForm">
              <el-option label="否" value="0"></el-option>
              <el-option label="普通" value="1"></el-option>
              <el-option label="重点" value="2"></el-option>
              <el-option label="特殊" value="3"></el-option>
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :xs="24" :sm="24" :md="24" :lg="6" :xl="6">
          <el-form-item label="养护类型：" prop="nurtureType">
            <el-select v-model="form.nurtureType" @change="updateForm">
              <el-option 
                v-for="item in nurtureOption" 
                :key="item.value" 
                :label="item.label" 
                :value="item.value">
              </el-option>
            </el-select>
          </el-form-item>
        </el-col>

        <!-- 限定备注 -->
        <el-col :xs="24" :sm="24" :md="24" :lg="24" :xl="24">
          <el-form-item label="限定备注：" prop="lmtUsedRemark">
            <el-input 
              type="textarea" 
              :rows="2" 
              v-model="form.lmtUsedRemark" 
              @blur="updateForm">
            </el-input>
          </el-form-item>
        </el-col>
      </el-row>
    </el-form>
  </div>
</template>

<script>
export default {
  props: {
    form: {
      type: Object,
      required: true
    },
    formDisabled: {
      type: Boolean,
      default: false
    },
    mode: {
      type: String,
      default: 'add' // 'add', 'edit', 'view'
    }
  },
  data() {
    return {
      // 选项数据
      YNoptions: [
        { id: 0, label: '否' },
        { id: 1, label: '是' }
      ],
      statusOptions: [
        { id: 0, label: '禁用' },
        { id: 1, label: '可用' }
      ],
	  addRules:{},
	  formDisabledAntcLv: true, // 默认禁用抗生素等级
      drugCategoryOption: [], // 药理类别选项
      drugCategoryChildOption: [], // 药理类别II选项
      threeLevelDrugCategoryOption: [], // 三级药理类别选项
      poisonousTypeOption: [], // 毒麻类型选项
      highRiskOption:[ // 高危
      	{ id:0,label:'非高危药品'},{ id:1,label:' A级高危'},{ id:2,label:'B级高危'},
      	{ id:3,label:'C级高危'},
      ],
      // liquidOptions: [], // 是否液体选项
      qualityCategory: [], // 质量类别选项
      basicTypeOptions: [], // 基药类型选项
	  saveOptions:[{ id:1,label:'常温(0~30°)'},{ id:2,label:'阴凉(2~20°)'}, { id:3,label:'冷藏(2~8°)'},{ id:4,label:'凉暗(2~20°且避光)'}],//储存条件
	  antcLvOption:[{id:1,label:'一级抗生素'},{id:2,label:'二级抗生素'},{id:3,label:'三级抗生素'}], //抗生素等级
      chargedSpcOptions:[{id:0,label:'全部'},{id:1,label:'门诊'},{id:2,label:'其他'},{id:3,label:'不计费'}], // 计费范围选项
	  UseOptions:[{ id:0,label:'全院',value:'全院'},{ id:1,label:'门诊',value:'门诊'},{ id:2,label:'其他',value:'其他'}], // 适用范围
      getEisaiOption: [], // 卫材类型选项
      eisaiAtteOption: [], // 卫材属性选项
      nurtureOption:[{ id:1,label:'常规养护',value:'常规养护'},{ id:2,label:'重点养护',value:'重点养护'}],
	  liquidOptions:[{ id:0,label:'非液体'},{ id:1,label:'大液体'},{ id:2,label:'小液体'}], // 是否液体
    };
  },
  methods: {
    updateForm() {
      this.$emit('update', this.form);
    },
	resetForm() {
	  // 重置所有字段
	  Object.keys(this.form).forEach(key => {
	    if (typeof this.form[key] === 'boolean') {
	      this.form[key] = false;
	    } else if (typeof this.form[key] === 'number') {
	      this.form[key] = 0;
	    } else {
	      this.form[key] = '';
	    }
	  });
	  
	  // 重置特定字段
	  this.form.highRisk = 0;
	  this.form.liquid = 0;
	  this.form.basMedn = 0;
	  this.form.antcLv = 0;
	  this.form.state = 1;
	  
	  // 重置表单验证
	  if (this.$refs.form) {
	    this.$refs.form.clearValidate();
	  }
	},
    setAntcStatus(isAntc) {
      // 根据抗生素否状态设置抗生素等级字段的禁用状态
      this.formDisabledAntcLv = !isAntc;
      this.updateForm();
    },
    // 这里可以添加获取选项数据的方法
    async fetchOptions() {
      // 示例：获取药理类别选项
      // const res = await getDrugCategory();
      // if (res.code === 200) {
      //   this.drugCategoryOption = res.data;
      // }
    }
  },
  created() {
    this.fetchOptions();
  }
};
</script>

<style lang="less" scoped>
/deep/ .el-form-item{
  margin-bottom: 8px;
}
.basic-info {
  padding: 4px;
  /deep/ .el-form-item__label{
    font-size: 12px;
  }
  /deep/ .el-input__inner{
    padding: 0 4px;
  }
  /deep/ .el-form-item__content{
    display: flex;
    justify-content: space-around;
  }
  /deep/ .el-input--mini .el-input__inner{
    height: 26px;
  }
}
</style>